package com.cn.wanxi.servlet.back.product;

import com.cn.wanxi.model.ProductTypeModel;
import com.cn.wanxi.service.IProductTypeService;
import com.cn.wanxi.service.impl.ProductTypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/back/product/type/add")
public class ProductTypeAddServlet extends HttpServlet {
    IProductTypeService productTypeService = new ProductTypeServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //产品类型添加
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String name = req.getParameter("name");
        ProductTypeModel productTypeModel = new ProductTypeModel();
        productTypeModel.setName(name);
        productTypeModel.setCreate_time(new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date().getTime()));
        int result = productTypeService.addProductType(productTypeModel);
        resp.getWriter().print(result);
    }
}
